var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "react", "mobile/services/shoppingService", "mobile/site", "maishu-ui-toolkit", "controls/spiner-component"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const React = require("react");
    const shoppingService_1 = require("mobile/services/shoppingService");
    const site_1 = require("mobile/site");
    const ui = require("maishu-ui-toolkit");
    const spiner_component_1 = require("controls/spiner-component");
    class StoreCouponsPage extends spiner_component_1.SpinerComponent {
        constructor(props) {
            super(props);
            this.shopping = this.props.createService(shoppingService_1.ShoppingService);
        }
        loadData() {
            return __awaiter(this, void 0, void 0, function* () {
                let coupons = yield this.shopping.storeCoupons();
                return { coupons };
            });
        }
        receiveCoupon(coupon) {
            return this.shopping.receiveCoupon(coupon.Id);
        }
        render() {
            let coupons = this.state.coupons;
            return React.createElement(React.Fragment, null,
                React.createElement("header", null, site_1.defaultNavBar(this.props.source, { title: '店铺优惠劵' })),
                React.createElement("section", null,
                    coupons.length > 0 ?
                        React.createElement("hr", null)
                        :
                            React.createElement("div", { className: "norecords" },
                                React.createElement("div", { className: "icon" },
                                    React.createElement("i", { className: "icon-money" })),
                                React.createElement("h4", { className: "text" }, "\u6682\u65E0\u53EF\u9886\u53D6\u7684\u4F18\u60E0\u5238")),
                    coupons.map(o => React.createElement("div", { key: o.Id },
                        React.createElement("div", { className: "coupon" },
                            React.createElement("button", { className: `pull-right receive available`, ref: (btn) => {
                                    if (!btn)
                                        return;
                                    btn.onclick = ui.buttonOnClick(() => {
                                        return this.receiveCoupon(o);
                                    }, { toast: '领取优惠劵成功' });
                                } }, "\u7ACB\u5373\u9886\u53D6"),
                            React.createElement("div", { className: "main" },
                                React.createElement("div", null,
                                    "\uFFE5",
                                    o.Discount),
                                React.createElement("div", { className: "date" },
                                    `有效期 ${o.ValidBegin.toLocaleDateString()} 至 ${o.ValidEnd.toLocaleDateString()}`,
                                    React.createElement("div", null, o.Amount ? React.createElement("span", null,
                                        "\u6EE1",
                                        o.Amount,
                                        "\u5143\u53EF\u4EE5\u4F7F\u7528") : React.createElement("span", null, "\u4EFB\u610F\u91D1\u989D\u53EF\u7528\u4F7F\u7528"))))),
                        React.createElement("hr", null)))));
        }
    }
    exports.default = StoreCouponsPage;
});
// export default function (page: Page) {
//     let shopping = page.createService(ShoppingService);
//     shopping.storeCoupons().then(coupons => {
//         // coupons = [];
//         ReactDOM.render(<StoreCouponsPage coupons={coupons} />, page.element);
//     });
// }
